package com.example.arithmeticleetcode.leetcode;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-05-15 15:56
 **/
public class Demo18 {

    public static void main(String[] args) {
        System.out.println(numberOfSteps(1));
        System.out.println(numberOfSteps(0));
        System.out.println(numberOfSteps(14));
        System.out.println(numberOfSteps(8));
        System.out.println(numberOfSteps(123));
    }

    public static int numberOfSteps(int num) {
        int count = 0;
        while (num > 0) {
            if (num % 2 == 0) {
                num /= 2;
            } else {
                num -= 1;
            }
            count++;
        }
        return count;
    }
}
